package com.zhongx.xingcd.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class FrameTao implements Filter {

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        //必须
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        //实际设置
        //response.setHeader("x-frame-options", "SAMEORIGIN");
        response.setHeader("Access-Control-Allow-Origin","*");//允许所有来源访问
        response.setHeader("Access-Control-Allow-Method","*");//允许访问的方式
        response.setHeader("Access-Control-Allow-Headers","Content-Type");
        response.setHeader("Access-Control-Allow-Credentials","true");

        //调用下一个过滤器（这是过滤器工作原理，不用动）
        chain.doFilter(request, response);
    }

    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }


}
